package com.heima.controller;

import com.heima.pojo.Node;
import com.heima.pojo.PageBean;
import com.heima.pojo.Region;
import com.heima.pojo.Region2;
import com.heima.pojo.dto.NodeQueryParamDto;
import com.heima.pojo.dto.RegionQueryParamDto;
import com.heima.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api("区域管理")
@RestController
@RequestMapping("/api/vm-service")
public class RegionController {
    @Autowired
    private RegionService regionService;
    @GetMapping("/region/search")
    @ApiOperation("区域分页查询")
    public PageBean selectRegionList(RegionQueryParamDto reginDto){
        return regionService.getRegionList(reginDto);
    }
    @PostMapping("/region")
    @ApiOperation("添加地区")
    public Boolean addRegion(@RequestBody Region2 region){
        log.info("添加的地区和信息是：{}",region);
        return regionService.addRegion(region);
    }
    @PutMapping("/region/{regionId}")
    public Boolean updateRegion(@PathVariable Long regionId,@RequestBody  Region2 region2){
        log.info("要修改的地区的信息为：{}{}",regionId,region2);
        return regionService.updateRegion(regionId,region2);
    }
    @ApiOperation("查看区域详情")
    @GetMapping("/node/search")
    public PageBean selectNode(NodeQueryParamDto nodeDto){
        log.info("要查看的id为{}",nodeDto.getRegionId());
        PageBean node =  regionService.selectNode(nodeDto);
        return node;
    }

    @ApiOperation("删除区域")
    @DeleteMapping("/region/{regionId}")
    public Boolean deleteRegion(@PathVariable String regionId){
        log.info("要删除的地区id：{}",regionId);
        return regionService.deleteRegion(regionId);
    }



}
